package com.example.javaee.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.javaee.common.result;
import com.example.javaee.entity.Asset;
import com.example.javaee.entity.AttackTask;
import com.example.javaee.entity.LateralMovement;
import com.example.javaee.service.LateralMovementService;
import com.example.javaee.service.VulnerabilityScanService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/lateralMovement")
public class LateralMovementController {
    @Autowired
    private LateralMovementService lateralMovementService;

    //新增横向移动
    @PostMapping("/add")
    public result<LateralMovement> add(HttpServletRequest request, @RequestBody LateralMovement lateralMovement) {

        LambdaQueryWrapper<LateralMovement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LateralMovement::getMoveName, lateralMovement.getMoveName());
        LateralMovement LM = lateralMovementService.getOne(queryWrapper);
        if (lateralMovementService.getOne(queryWrapper) != null) {
            return result.error("已存在");
        }
        lateralMovementService.save(lateralMovement);
        return result.success(null, "资产添加成功");
    }
    //横向接口列表

    @GetMapping("/getAssets/{pg}")
    public result<Page> page(@PathVariable Integer pg){
        //分页构造器
        Page<LateralMovement> pageInfo = new Page<>(pg,12);
        //条件构造器
        LambdaQueryWrapper<LateralMovement> queryWrapper = new LambdaQueryWrapper<>();
        //分页查询
        lateralMovementService.page(pageInfo,queryWrapper);
        System.out.printf(String.valueOf(pageInfo));
        return result.success(pageInfo,"查询成功");

    }


}
